package com.wave.web.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.wave.common.annotation.Log;
import com.wave.common.annotation.RepeatSubmit;
import com.wave.common.core.controller.BaseController;
import com.wave.common.core.domain.PageQuery;
import com.wave.common.core.domain.R;
import com.wave.common.core.page.TableDataInfo;
import com.wave.common.core.validate.AddGroup;
import com.wave.common.core.validate.EditGroup;
import com.wave.common.enums.BusinessType;
import com.wave.common.utils.poi.ExcelUtil;
import com.wave.system.domain.bo.SysDeviceSettingBo;
import com.wave.system.domain.vo.SysDeviceSettingVo;
import com.wave.system.service.ISysDeviceSettingService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 设备设置
 *
 * @author wave
 * @date 2024-10-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/deviceSetting")
public class SysDeviceSettingController extends BaseController {

    private final ISysDeviceSettingService iSysDeviceSettingService;

    /**
     * 查询设备设置列表
     */
    @SaCheckPermission("system:deviceSetting:list")
    @GetMapping("/list")
    public TableDataInfo<SysDeviceSettingVo> list(SysDeviceSettingBo bo, PageQuery pageQuery) {
        return iSysDeviceSettingService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出设备设置列表
     */
    @SaCheckPermission("system:deviceSetting:export")
    @Log(title = "设备设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysDeviceSettingBo bo, HttpServletResponse response) {
        List<SysDeviceSettingVo> list = iSysDeviceSettingService.queryList(bo);
        ExcelUtil.exportExcel(list, "设备设置", SysDeviceSettingVo.class, response);
    }

    /**
     * 获取设备设置详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:deviceSetting:query")
    @GetMapping("/{id}")
    public R<SysDeviceSettingVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iSysDeviceSettingService.queryById(id));
    }

    /**
     * 新增设备设置
     */
    @SaCheckPermission("system:deviceSetting:add")
    @Log(title = "设备设置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysDeviceSettingBo bo) {
        return toAjax(iSysDeviceSettingService.insertByBo(bo));
    }

    /**
     * 修改设备设置
     */
    @SaCheckPermission("system:deviceSetting:edit")
    @Log(title = "设备设置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysDeviceSettingBo bo) {
        return toAjax(iSysDeviceSettingService.updateByBo(bo));
    }

    /**
     * 删除设备设置
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:deviceSetting:remove")
    @Log(title = "设备设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iSysDeviceSettingService.deleteWithValidByIds(Arrays.asList(ids), true));
    }


    /**
     * 查询所有设备设置列表
     */
    @GetMapping("/listAll")
    @Log(title = "查询所有设备设置", businessType = BusinessType.OTHER)
    public R<List<SysDeviceSettingVo>> listAll(SysDeviceSettingBo bo) {
        List<SysDeviceSettingVo> list = iSysDeviceSettingService.queryList(bo);
        return R.ok(list);
    }
}
